package com.jiaquyun.jcyx.main.goods.adapter

import android.graphics.Typeface
import android.widget.TextView
import com.blankj.utilcode.util.ColorUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.jiaquyun.jcyx.R
import com.jiaquyun.jcyx.entity.Cat

class CateOneAdapter : BaseQuickAdapter<Cat, BaseViewHolder>(R.layout.item_category_one) {

    var selectedPosition = 0
        set(value) {
            if (field != value) {
                field = value
                notifyDataSetChanged()
            }
        }

    override fun convert(holder: BaseViewHolder, item: Cat) {
        holder.setText(R.id.tvCategoryTitleName, item.name)

        holder.getView<TextView>(R.id.tvCategoryTitleName).apply {
            if (holder.layoutPosition == selectedPosition) {
                setTypeface(null, Typeface.BOLD)
                setTextColor(ColorUtils.getColor(R.color.colorMain))
                textSize = 14f
            } else {
                setTypeface(null, Typeface.NORMAL)
                setTextColor(ColorUtils.getColor(R.color.FF_333333))
                textSize = 13f
            }
        }

        holder.itemView.isSelected = holder.layoutPosition == selectedPosition
    }
}

class CateTwoAdapter : BaseQuickAdapter<Cat, BaseViewHolder>(R.layout.item_category_two) {

    var selectedPosition = 0
        set(value) {
            if (field != value) {
                field = value
                notifyDataSetChanged()
            }
        }

    override fun convert(holder: BaseViewHolder, item: Cat) {
        holder.setText(R.id.rvCategoryName, item.name)

        holder.itemView.isSelected = holder.layoutPosition == selectedPosition
    }
}